package com.mes.biz.service.impl;

import java.util.List;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.pagehelper.PageInfo;
import com.mes.common.core.domain.BaseEntity;
import com.mes.common.core.service.BaseServiceImpl;
import com.mes.biz.mapper.BizProductWarehouseMapper;
import com.mes.biz.domain.BizProductWarehouse;
import com.mes.biz.service.BizProductWarehouseService;
import org.springframework.transaction.annotation.Transactional;
import com.mes.common.exception.BizException;
import org.springframework.util.CollectionUtils;

/**
 * 成品仓库档案Service业务层处理
 * @author hwg
 * @email hwg
 * @date 2023-04-30
 */
@Service
@Transactional(readOnly = true)
public class BizProductWarehouseServiceImpl extends BaseServiceImpl<BizProductWarehouseMapper, BizProductWarehouse> implements BizProductWarehouseService {

    private static final Logger log = LoggerFactory.getLogger(BizProductWarehouseServiceImpl.class);

    /**
     * 获取单条数据
     * @param bizProductWarehouse 成品仓库档案
     * @return 成品仓库档案
     */
    @Override
    public BizProductWarehouse get(BizProductWarehouse bizProductWarehouse) {
        BizProductWarehouse dto = super.get(bizProductWarehouse);
        return dto;
    }

    /**
     * 获取单条数据
     * @param id 成品仓库档案id
     * @return 成品仓库档案
     */
    @Override
    public BizProductWarehouse get(String id) {
        BizProductWarehouse dto = super.get(id);
        return dto;
    }

    /**
     * 查询成品仓库档案列表
     * @param bizProductWarehouse 成品仓库档案
     * @return 成品仓库档案
     */
    @Override
    public List<BizProductWarehouse> findList(BizProductWarehouse bizProductWarehouse) {
		List<BizProductWarehouse> bizProductWarehouseList = super.findList(bizProductWarehouse);
        return bizProductWarehouseList;
    }

    /**
     * 分页查询成品仓库档案列表
     * @param bizProductWarehouse 成品仓库档案
     * @return 成品仓库档案
     */
    @Override
    public PageInfo<BizProductWarehouse> findPage(BizProductWarehouse bizProductWarehouse) {
		PageInfo<BizProductWarehouse> page = super.findPage(bizProductWarehouse);
        return page;
    }

    /**
     * 保存成品仓库档案
     * @param bizProductWarehouse
     * @return 结果
     */
    @Override
    public boolean save(BizProductWarehouse bizProductWarehouse) {
        checkPostionUnique(bizProductWarehouse);
        return super.save(bizProductWarehouse);
    }

    /**
     * 校验位置的唯一性
     * @param bizProductWarehouse
     */
    @Override
    public void checkPostionUnique(BizProductWarehouse bizProductWarehouse) {
        BizProductWarehouse bizProductWarehouseUnique = new BizProductWarehouse();
        bizProductWarehouseUnique.setNotEqualId(bizProductWarehouse.getId());
        bizProductWarehouseUnique.setPostion(bizProductWarehouse.getPostion());
        if (!CollectionUtils.isEmpty(mapper.findListWithUnique(bizProductWarehouseUnique))) {
            throw new BizException("位置已存在，请重新输入！");
        }
    }

    /**
     * 删除成品仓库档案信息
     * @param bizProductWarehouse
     * @return 结果
     */
    @Override
    public boolean remove(BizProductWarehouse bizProductWarehouse) {
        return super.remove(bizProductWarehouse);
    }

    /**
     * 批量删除成品仓库档案
     * @param ids 需要删除的成品仓库档案ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteBizProductWarehouseByIds(String[] ids) {
        return mapper.deleteBizProductWarehouseByIds(ids, BaseEntity.DEL_FLAG_DELETE);
    }

}
